import { _decorator, Component, Node, Label, tween, view, UITransform, Vec3, SpriteAtlas, SpriteFrame, Sprite, UIOpacity, EventTouch, Toggle } from 'cc';
import { App } from '../App';
import AbstractComponent from '../base/AbstractComponent';
import { localKey } from '../common/Common';
import { LoadMg } from '../tools/LoadMg';
import { setLanguagePopuUp, showTipBox } from '../tools/PopuUp';
import UtilTool from '../tools/UtilTool';
const { ccclass, property } = _decorator;

// 设置界面
@ccclass('SettingPanel')
export class SettingPanel extends AbstractComponent {
    @property(Node)
    contentNode: Node = null;

    @property(Toggle)
    soundToggle: Toggle = null;

    @property(Toggle)
    musicToggle: Toggle = null;

    @property(Node)
    languageNode: Node = null;
   
    onLoad() {
        UtilTool.setScreen(this.node)
        UtilTool.nodeActive(this.contentNode,5,0.16)
    }

    start() {
        this.soundToggle.isChecked = App.EFFECT_SW=="1"
        this.musicToggle.isChecked = App.MUSIC_SW=="1"

    }

    /** 
     * 切换音效
      */
    switchSound(event: Event, customEventData: string) {
        App.Audio.playOneShot("click")
        App.setEffect(!this.soundToggle.isChecked)
    }

    /** 
     * 切换音乐
      */
    switchMSusic(event: Event, customEventData: string) {
        App.Audio.playOneShot("click")
        App.setMusic(!this.musicToggle.isChecked)
    }

    /** 
     * 关闭
      */
    clickClose() {
        App.Audio.playOneShot("click")
        this.node.destroy();
    }

    /** 
     * 点击语言
      */
    clickLanguage() {
        App.Audio.playOneShot("click")
        setLanguagePopuUp(this.node)
    }

    // 切换账号
    clickSwitchAccount() {
        this.playClickAudio()

        let cb = (btnIndex)=>{
            if(btnIndex == 0){
                this.backToLogin()
            }
        }

        // 显示提示框
        showTipBox({
            content : App.language.getLanguageLab(2043),
            btnType : 4,
            func : cb,
        })

    }
}

